package com.lrkj.property.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.property.domain.Room;
import com.lrkj.property.service.IRoomService;
import com.lrkj.property.vo.BatchRoomVo;
import com.lrkj.property.vo.RoomVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 房屋管理Controller
 *
 * @author yajun_ren
 * @date 2021-07-22
 */
@Api(tags = "房屋管理")
@RestController
@RequestMapping("/property/room")
public class RoomController extends BaseController {
    @Autowired
    private IRoomService roomService;

    /**
     * 查询房屋管理列表
     */
    @ApiOperation(value = "查询房屋管理列表", notes = "查询房屋管理列表")
    @PreAuthorize("@ss.hasPermi('property:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(Room room) {
        startPage();
        List<Room> list = roomService.selectRoomList(room);
        return getDataTable(list);
    }

    /**
     * 导出房屋管理列表
     */
    @ApiOperation(value = "导出房屋管理列表", notes = "导出房屋管理列表")
    @PreAuthorize("@ss.hasPermi('property:room:export')")
    @Log(title = "房屋管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Room room) {
        List<Room> list = roomService.selectRoomList(room);
        ExcelUtil<Room> util = new ExcelUtil<Room>(Room.class);
        return util.exportExcel(list, "房屋管理数据");
    }

    /**
     * 获取房屋管理详细信息
     */
    @ApiOperation(value = "获取房屋管理详细信息", notes = "获取房屋管理详细信息")
    @PreAuthorize("@ss.hasPermi('property:room:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(roomService.selectRoomById(id));
    }

    /**
     * 新增房屋管理
     */
    @ApiOperation(value = "新增房屋管理", notes = "新增房屋管理")
    @PreAuthorize("@ss.hasPermi('property:room:add')")
    @Log(title = "房屋管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Room room) {
        return toAjax(roomService.insertRoom(room));
    }

    /**
     * 修改房屋管理
     */
    @ApiOperation(value = "修改房屋管理", notes = "修改房屋管理")
    @PreAuthorize("@ss.hasPermi('property:room:edit')")
    @Log(title = "房屋管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Room room) {
        return toAjax(roomService.updateRoom(room));
    }

    /**
     * 删除房屋管理
     */
    @ApiOperation(value = "删除房屋管理", notes = "删除房屋管理")
    @PreAuthorize("@ss.hasPermi('property:room:remove')")
    @Log(title = "房屋管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(roomService.deleteRoomByIds(ids));
    }

    /**
     * 新增楼层数量
     */
    @ApiOperation(value = "新增楼层数量", notes = "新增楼层数量")
    @PreAuthorize("@ss.hasPermi('property:room:addLayerNum')")
    @PostMapping("/addLayerNum")
    public AjaxResult addLayerNum(@RequestBody RoomVo roomVo) {
        return toAjax(roomService.addLayerNum(roomVo));
    }

    /**
     * 新增房屋数量
     */
    @ApiOperation(value = "新增房屋数量", notes = "新增房屋数量")
    @PreAuthorize("@ss.hasPermi('property:room:addRoomNum')")
    @PostMapping("/addRoomNum")
    public AjaxResult addRoomNum(@RequestBody RoomVo roomVo) {
        return toAjax(roomService.addRoomNum(roomVo));
    }




    /**
     * 统计房间数量信息
     */
    @ApiOperation(value = "统计房间数量信息", notes = "统计房间数量信息")
    @GetMapping(value = "/censusRoomInfo")
    public AjaxResult censusRoomInfo(Room room)
    {
        return AjaxResult.success(roomService.censusRoomInfo(room));
    }

    /**
     * 批量修改房屋管理
     */
    @ApiOperation(value = "批量修改房屋管理", notes = "批量修改房屋管理")
    @Log(title = "批量修改房屋管理", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('property:room:batchUpdateRoom')")
    @PutMapping("/batchUpdateRoom")
    public AjaxResult batchUpdateRoom(@RequestBody BatchRoomVo batchRoomVo) {
        return toAjax(roomService.batchUpdateRoom(batchRoomVo));
    }

}
